﻿@using CRM.Admin.Areas.Customer.Controllers
@{
    ViewBag.Title = "PurchaseAdd";
}
@section head
{
    <script src="@Url.Content("~/ScriptPlugin/validate/validate.js")"></script>
    <link href="@Url.Content("~/ScriptPlugin/validate/validate.css")" rel="stylesheet" />
    <script type="text/javascript" src="@Url.Content("~/Scripts/form2json.js")"></script>
    <script type="text/javascript">
        function SaveData(index) {
            if (K.Validate())
            {
                var dto = $('#productForm').serializeJson();
                K.AjaxJson("@Url.Content("~/Customer/Purchase/PurchaseInsert")", dto, function (result) {
                    parent.K.layer.callback(index, result, dto);
                    parent.K.layer.close(index);
                });
            }
        }
    </script>
}
<form action="" id="productForm" name="productForm">
    <div class="content-form">
        <table class="content-table">
            <tr>
                <th><span>采购品种</span></th>
                <td>
                    <input type="hidden" id="CustomerId" name="CustomerId" value="@ViewBag.CustomerId" />
                    <input type="hidden" id="Id" name="Id" value="@Guid.NewGuid()" />
                    <input type="text" data-valid="required" id="BreedName" name="BreedName" readonly="readonly" class="p-icon-right p-icon-customer" onclick="GetBreed()" />
                    <input type="hidden" id="BreedId" name="BreedId" />
                </td>
                <th>原料材质</th>
                <td>
                    <input type="text" id="MaterialMade" name="MaterialMade" data-rule-number="true"  />
                </td>
            </tr>
            <tr>
                <th>供应源</th>
                <td>
                    <select id="Type" name="Type" onchange="setType()">
                        <option value="0">厂商</option>
                        <option value="1">经销商</option>
                    </select>
                </td>
                <th>
                    <span id="typetd">厂商名称</span>
                </th>
                <td>
                    <div id="purchasepannel">
                        <input type="text" data-valid="required" readonly="readonly" id="SupplierName" name="SupplierName" onclick="GetSteel()" class="p-icon-right p-icon-customer" />
                    </div>
                    <input type="hidden" id="SteelId" name="SteelId"/>
                </td>
            </tr>
            <tr>
                <th>
                    <span>采购重量</span>
                </th>
                <td>
                    <input type="text" id="Weight" name="Weight" data-rule-number="true" data-valid="required" value="0"/>
                </td>
                <th>采购时间(年)</th>
                <td>
                    <select id="Year" name="Year">
                        @{

                            int year = DateTime.Now.Year;
                            IList<int> yearList = new List<int>();
                            for (int i = year; i >= 2014; i--)
                            {
                                yearList.Add(i);
                                <option value="@i">@i</option>
                            }
                        }
                    </select>
                </td>
            </tr>
        </table>
    </div>
</form>
@section foot
{
    <script type="text/javascript">
        function GetBreed() {
            K.layer.iframe({
                title: "@Html.GetLayerTitle(LayerIcon.Add, "选择钢材品种")",
                content: "@Url.Content("~/Sys/Dictionary/DictionaryCheck")?TypeCode=@CustomerInfoController.DicCatalogType.GCPZ",
                maxmin: true,
                area: ["80%", "80%"],
                callback: function(rows) {
                    if(rows && rows.length > 0)
                    {
                        $("#BreedName").val(rows[0].Name);
                        $("#BreedId").val(rows[0].Id);
                    }
                }
            });
        }
        function setType() {
            var val = $("#Type").val();
            if (val == "0") {
                $("#purchasepannel").html("<input type=\"text\" data-valid=\"required\" readonly=\"readonly\" id=\"SupplierName\" name=\"SupplierName\" onclick=\"GetSteel()\" class=\"p-icon-right p-icon-customer\" />");
                $("#typetd").html("厂商名称");
            } else {
                $("#purchasepannel").html("<input type=\"text\" data-valid=\"required\"  id=\"SupplierName\" name=\"SupplierName\" />");
                $("#SteelId").val("");
                $("#typetd").html("供应商名称");
            }
        }
        function GetSteel() {
            K.layer.iframe({
                title: "@Html.GetLayerTitle(LayerIcon.Add, "选择钢材品种")",
                content: "@Url.Content("~/Customer/Steel/SteelCheck")?Multi=false",
                maxmin: true,
                area: ["80%", "80%"],
                callback: function(rows) {
                    if(rows && rows.length > 0)
                    {
                        $("#SupplierName").val(rows[0].Name);
                        $("#SteelId").val(rows[0].Id);
                    }
                }
            });
        }
        
    </script>
}